package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.attr;


import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.client.vo.scene.CommonAttrVO;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.iwhalecloud.bss.kite.web.service.accept.attr.handler.AbstractAttrHandler;
import com.ztesoft.bss.base.staticdata.ServiceOfferConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wanghl386
 * @Description
 * @Date 2022/1/10 15:14
 */

@Service
public class JPWOpenWayHandler extends AbstractAttrHandler {

    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Override
    public void init(CommonAttrVO commonAttrVO) {

    }

    @Override
    public DataResult<Boolean> apply(String sceneInstId, String fieldName, String value, String valueDesc) {
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(sceneInstId);
        List<String> serviceOfferIdList = querySceneInstService.getExtParameterValue(sceneInstId, "BUSI_CHANGE_SERVICEOFFERID");
        if(ServiceOfferConst.service_offer_2826.equals(sceneInst.getServiceOfferId())){
            /**产品变更时当变更类型选择资料变更、资费变更和临时调速时开通方式默认无需核查直开，不允许修改；
             * 当变更类型选择有除资料变更、资费变更别的类型时，开通方式默认先核查再开通，不允许修改。
             */
            KiteAttr openWayAttr = querySceneInstService.getCommonAttr(sceneInstId, "ORD10005");
            if(!KiteObjectUtils.isEmpty(serviceOfferIdList)){
                if(serviceOfferIdList.stream().allMatch(serviceOfferId -> KiteStringUtils.equalsAny(serviceOfferId,"1100","1009","1091"))){
                    value="0";
                    valueDesc="无需核查直开";
                    openWayAttr.setValue("0");
                    openWayAttr.setValueDesc("无需核查直开");
                }else{
                    openWayAttr.setValue("2");
                    value="2";
                    valueDesc="先核查再开通";

                }
            }
        }

        return super.apply(sceneInstId, fieldName, value, valueDesc);
    }
}
